
if( window.runtime.platform=='nw.js' ) {
    var fs = window.require("fs")
}

import promiseWrapper from './promiseWrapper'

export const stat: any = promiseWrapper(fs?.stat)
export const readdir: any = promiseWrapper(fs?.readdir)
export const exists: any = promiseWrapper(fs?.exists, true)
export const readFile: any = promiseWrapper(fs?.readFile)
export const writeFile: any = promiseWrapper(fs?.writeFile)
export const mkdir: any = promiseWrapper(fs?.mkdir)
export const unlink: any = promiseWrapper(fs?.unlink)
export function isFile(path:string) {
    return new Promise(resovle=>{
        fs?.stat(path, (err: any, stats: any)=>{
            err? resovle(false) : resovle(stats.isFile())
        })
    })
}
export function isDir(path:string) {
    return new Promise(resovle=>{
        fs?.stat(path, (err: any, stats: any)=>{
            err? resovle(false) : resovle(stats.isDirectory())
        })
    })
}
